/*
 * This file is part of GuitarMaster.
 * 
 * GuitarMaster is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GuitarMaster is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.paris5.master2.guitarmaster.entity;

import com.paris5.master2.guitarmaster.bean.EcomProduct;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Leticia Mahamed, Alice Khammy, mourad nedjahi, Saliou Mamadou Barry
 */
@Entity
@Table(name = "product")
public class Product implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_product", nullable = false)
    private Integer idProduct;
    
    @Column(name = "bid_end_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date bidEndDate;
    
    @Column(name = "update_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateDate;
    
    @Column(name = "create_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createDate;
    
    @Column(name = "status")
    private Integer status;
    
    @JoinColumn(name = "id_store", referencedColumnName = "id_store")
    @ManyToOne
    private Store idStore;
    
    @ManyToOne
    @JoinColumn(name="id_product_type")
    private ProductType idProductType;

    public Product() {
    }
    
    public Product(EcomProduct pt){
        idProduct=pt.getIdProduct();
        bidEndDate=pt.getBidEndDate();
        updateDate = pt.getUpdateDate();
        createDate = pt.getCreateDate();
        status = pt.getStatus();
        idStore = new Store(pt.getStore());
        idProductType = new ProductType(pt);
    }
    
    public EcomProduct getEcomProduct(){
        EcomProduct p = new EcomProduct();
        p.setIdProduct(idProduct);
        p.setBidEndDate(bidEndDate);
        p.setUpdateDate(updateDate);
        p.setCreateDate(createDate);
        p.setStatus(status);
        p.setIdStore(idStore.getEcomStore());
        p.setIdProductType(idProductType.getIdProductType());
        p.setTitle(idProductType.getTitle());
        p.setDescription(idProductType.getDescription());
        p.setPrice(idProductType.getPrice());
        p.setScore(idProductType.getScore().getEcomScore());
        p.setPhoto(idProductType.getPhoto());
        p.setCategory(idProductType.getIdCategory().getEcomCategory());
        return p;
    }

    public Product(Integer idProduct) {
        this.idProduct = idProduct;
    }

    public Integer getIdProduct() {
        return idProduct;
    }

    public void setIdProduct(Integer idProduct) {
        this.idProduct = idProduct;
    }

    public Date getBidEndDate() {
        return bidEndDate;
    }

    public void setBidEndDate(Date bidEndDate) {
        this.bidEndDate = bidEndDate;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Store getIdStore() {
        return idStore;
    }

    public void setIdStore(Store idStore) {
        this.idStore = idStore;
    }

    public ProductType getIdProductType() {
        return idProductType;
    }

    public void setIdProductType(ProductType idProductType) {
        this.idProductType = idProductType;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idProduct != null ? idProduct.hashCode() : 0);
        return hash;
    }
    
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.idProduct == null && other.idProduct != null) || (this.idProduct != null && !this.idProduct.equals(other.idProduct))) {
            return false;
        }
        return true;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }
}
